# 字典
# 作业1
dic = {"k1": "v1", "k2": "v2", "k3": [10, 20, 30]}
# 1.1
dic.setdefault("k4", "v4")
print(dic)
# 1.2
dic["k1"] = "小白"
print(dic)
# 1.3
dic["k3"].append(40)
print(dic)
# 1,4
dic["k3"].insert(0, 18)
print(dic)
# 作业2
name_list = ["路飞", "漩涡鸣人", "江户川柯南", "炭治郎", "孙悟空"]
name_dict = {}
for name in name_list:
    name_dict.setdefault(name, len(name))
print(name_dict)
# 集合
# 作业1
num_list1 = [2, 7, 4, 2, 9, 3, 8, 6, 2, 4]
num_set1 = set(num_list1)
num_list2 = list(num_set1)
print(num_list2)
# 作业2
name_set2 = set()
while True:
    name = input("请输入游戏角色名称（输入0退出输入）：")
    if name == "0":
        break
    elif name not in name_set2:
        name_set2.add(name)
    else:
        print(f"{name}已经记录")
        print(name_set2)
